﻿create PROCEDURE Sync.SP_CustomerLoans_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanID],
		g.[LoanNumber],g.[CustomerID],g.[ProjectStageID],g.[CommitteeID],g.[LoanName],g.[LoanPaymentMethodID],g.[ResponsibleID],g.[IsLoanProjectExist],g.[LoanPlaceTypeID],g.[LoanAmount],g.[LoanPaymentPeriod],g.[LegalFormID],g.[LoanCreatedDate],g.[LoanTypeID],g.[RelationWithManagers],g.[ReceiptID],g.[FamilyCurrentDebts],g.[LoanAddress],g.[GuarantorID],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[CustomerLoans] g RIGHT JOIN Sync.CustomerLoans_Tracking t  
    ON t.LoanID = g.LoanID 
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
        AND (@FilterdColumn IS NULL OR g.CommitteeID = @FilterdColumn)
    END














